package com.wpml.common.util;

import lombok.*;
import lombok.experimental.Accessors;

/**
 * @description:
 * @author: wp
 * @date: 2019-09-02 10:43
 **/
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class RUtil<T> {

    public static final Integer SUCCESS = 200;
    public static final Integer ERROR = 500;
    public static final Integer FAIL = -1;
    public static final String SUCCESS_MSG = "操作成功";
    public static final String FAIL_MSG = "操作失败";
    public static final String ERROR_MSG = "系统异常";

    private int status;

    private String msg;

    private T data;

    private Integer total;

    public RUtil<T> ok() {
        return new RUtil<T>().setStatus(SUCCESS).setMsg(SUCCESS_MSG);
    }

    public RUtil<T> ok(T data) {
        return new RUtil<T>().setStatus(SUCCESS).setMsg(SUCCESS_MSG).setData(data);
    }

    public RUtil<T> ok(T pageList, int total) {
        return new RUtil<T>(SUCCESS, SUCCESS_MSG, pageList, total);
    }

    public RUtil<T> fail(String msg) {
        return new RUtil<T>().setStatus(FAIL).setMsg(msg);
    }

}
